package com.smart.village.big.screen.service.impl;

import com.alibaba.fastjson.JSONObject;
import com.smart.village.big.screen.domain.PartyMemberInformationStaticVo;
import com.smart.village.big.screen.mapper.PartyMemberInformationMapper;
import com.smart.village.big.screen.service.PartyMemberInformationService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.util.ObjectUtils;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;

@Service
public class PartyMemberInformationServiceImpl implements PartyMemberInformationService {

    @Autowired
    private PartyMemberInformationMapper partyMemberInformationMapper;

    @Override
    public List<List<JSONObject>> getPartyMemberStatic(String partyOrganizationSerialNumber) {
        List<List<JSONObject>> resultJsonList = new ArrayList<>();
        PartyMemberInformationStaticVo partyMemberStatic = partyMemberInformationMapper.getPartyMemberStatic(partyOrganizationSerialNumber);

        if (!ObjectUtils.isEmpty(partyMemberStatic)) {
            getListGender(partyMemberStatic, resultJsonList);
            getListEducate(partyMemberStatic, resultJsonList);
            getListAge(partyMemberStatic, resultJsonList);
            getListType(partyMemberStatic, resultJsonList);
        }
        return resultJsonList;
    }

    private static void getListGender(PartyMemberInformationStaticVo partyMemberStatic, List<List<JSONObject>> resultJsonList) {
        List<JSONObject> listGender = new ArrayList<>();
        JSONObject nan = new JSONObject();
        nan.put("value", partyMemberStatic.getMale());
        nan.put("name", "男");
        JSONObject nv = new JSONObject();
        nv.put("value", partyMemberStatic.getFemale());
        nv.put("name", "女");
        listGender.add(nan);
        listGender.add(nv);
        resultJsonList.add(listGender);
    }

    private static void getListEducate(PartyMemberInformationStaticVo partyMemberStatic, List<List<JSONObject>> resultJsonList) {
        List<JSONObject> listEducate = new ArrayList<>();
        JSONObject belowJunior = new JSONObject();
        belowJunior.put("value", partyMemberStatic.getBelowJunior());
        belowJunior.put("name", "初中及以下");
        listEducate.add(belowJunior);
        JSONObject highSchool = new JSONObject();
        highSchool.put("value", partyMemberStatic.getHighSchool());
        highSchool.put("name", "高中");
        listEducate.add(highSchool);
        JSONObject secondaryProfessionalSchool = new JSONObject();
        secondaryProfessionalSchool.put("value", partyMemberStatic.getSecondaryProfessionalSchool());
        secondaryProfessionalSchool.put("name", "中专/中技");
        listEducate.add(secondaryProfessionalSchool);
        JSONObject juniorCollege = new JSONObject();
        juniorCollege.put("value", partyMemberStatic.getJuniorCollege());
        juniorCollege.put("name", "大专");
        listEducate.add(juniorCollege);
        JSONObject undergraduate = new JSONObject();
        undergraduate.put("value", partyMemberStatic.getUndergraduate());
        undergraduate.put("name", "本科");
        listEducate.add(undergraduate);
        JSONObject master = new JSONObject();
        master.put("value", partyMemberStatic.getMaster());
        master.put("name", "硕士");
        listEducate.add(master);
        JSONObject doctor = new JSONObject();
        doctor.put("value", partyMemberStatic.getDoctor());
        doctor.put("name", "博士");
        listEducate.add(doctor);
        resultJsonList.add(listEducate);
    }

    private static void getListAge(PartyMemberInformationStaticVo partyMemberStatic, List<List<JSONObject>> resultJsonList) {
        List<JSONObject> listAge = new ArrayList<>();
        JSONObject twenty = new JSONObject();
        twenty.put("value", partyMemberStatic.getTwenty());
        twenty.put("name", "30岁以下");
        listAge.add(twenty);
        JSONObject thirty = new JSONObject();
        thirty.put("value", partyMemberStatic.getThirty());
        thirty.put("name", "31-41岁");
        listAge.add(thirty);
        JSONObject forty = new JSONObject();
        forty.put("value", partyMemberStatic.getForty());
        forty.put("name", "41-51岁");
        listAge.add(forty);
        JSONObject fifty = new JSONObject();
        fifty.put("value", partyMemberStatic.getFifty());
        fifty.put("name", "51-61岁");
        listAge.add(fifty);
        JSONObject sixty = new JSONObject();
        sixty.put("value", partyMemberStatic.getSixty());
        sixty.put("name", "61岁以上");
        listAge.add(sixty);
        resultJsonList.add(listAge);
    }
    private static void getListType(PartyMemberInformationStaticVo partyMemberStatic, List<List<JSONObject>> resultJsonList) {
        List<JSONObject> listType = new ArrayList<>();
        JSONObject working = new JSONObject();
        working.put("value", partyMemberStatic.getWorking());
        working.put("name", "在职党员");
        listType.add(working);
        JSONObject quit = new JSONObject();
        quit.put("value", partyMemberStatic.getQuit());
        quit.put("name", "离退休党员");
        listType.add(quit);
        JSONObject other = new JSONObject();
        other.put("value", partyMemberStatic.getOther());
        other.put("name", "其它党员");
        listType.add(other);
        JSONObject farmer = new JSONObject();
        farmer.put("value", partyMemberStatic.getFarmer());
        farmer.put("name", "农民党员");
        listType.add(farmer);
        resultJsonList.add(listType);
    }
    @Override
    public List<HashMap<String, Object>> getPartyMemberStaticDetail(String partyOrganizationSerialNumber) {
        return partyMemberInformationMapper.getPartyMemberStaticDetail(partyOrganizationSerialNumber);
    }


}
